
--[[

    slimui - Copyright (c) 2011 atom0s, All rights reserved.

    See Copyright notice in slimui.lua
    
]]--

class 'Timer: Component' { ... };

----------------------------------------------------------------------------------
-- func: Timer.__init__
-- desc: Constructor called when this object is first created.
----------------------------------------------------------------------------------
function Timer.__init__( self )
    Component.__init__( self );
end

----------------------------------------------------------------------------------
-- func: Timer:Create
-- desc: Creates a new Timer object.
----------------------------------------------------------------------------------
function Timer:Create( parent, enabled )
    if parent == nil or parent._object == nil then
        if slimui:isdebug() then
            slimui:msg( 'Timer:Create - creating a timer without parent; you must destroy this object yourself!' );
        end
    end
    
    if enabled == nil then enabled = true; end
    
    self._object = createTimer( parent._object, enabled );
    
    if self._object == nil then
        slimui:err( 'Timer:Create failed to initialize a new object.' );
    end
    
    return self;
end

----------------------------------------------------------------------------------
-- func: Timer:SetInterval
-- desc: Sets the interval for this timer object.
----------------------------------------------------------------------------------
function Timer:SetInterval( interval )
    timer_setInterval( self._object, interval );
end

----------------------------------------------------------------------------------
-- func: Timer:GetEnabled
-- desc: Returns the enabled status of this timer.
----------------------------------------------------------------------------------
function Timer:GetEnabled( )
    return timer_getEnabled( self._object );
end

----------------------------------------------------------------------------------
-- func: Timer:SetEnabled
-- desc: Sets the enabled status of this timer.
----------------------------------------------------------------------------------
function Timer:SetEnabled( enabled )
    timer_setEnabled( self._object, enabled );
end

----------------------------------------------------------------------------------
-- func: Timer:OnTimer
-- desc: Sets the OnTimer event handler for this timer.
----------------------------------------------------------------------------------
function Timer:OnTimer( func )
    timer_onTimer( self._object, func );
end



--[[ Debug information. ]]--------------------------------------------------------
if ( slimui:isdebug() == true ) then
    slimui:msg( '(Control) timer.lua successfully loaded.' );
end